package io.renren.modules.poschangerecord.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.poschangerecord.entity.PreposEntity;
import io.renren.modules.poschangerecord.service.impl.PoschangerecordtableServiceImpl;
import io.renren.modules.user.entity.UserinfoEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.poschangerecord.entity.PoschangerecordtableEntity;
import io.renren.modules.poschangerecord.service.PoschangerecordtableService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

@RestController
@RequestMapping("poschangerecord/poschangerecordtable")
public class PoschangerecordtableController {
    @Autowired
    private PoschangerecordtableService poschangerecordtableService;

    @GetMapping("uuTest")
    public List<PoschangerecordtableServiceImpl.Mat> uuTest(@RequestParam("matid") String matid){
      return poschangerecordtableService.selectByMatid(matid);
    }
    @GetMapping("getPre")
    public List<PreposEntity> getPre(@RequestParam("matid") String matid){
        return poschangerecordtableService.getPre(matid);
    }

    /**
     * 物料信息
     */

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("poschangerecord:poschangerecordtable:list")
    public R list(@RequestParam Map<String, Object> params){
       // PageUtils page = poschangerecordtableService.queryPage(params);
        // 分页
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
        String matid = String.valueOf(params.get("key"));
        Page<PoschangerecordtableEntity> page = new Page<>(pageIndex,pageSize);

        // 通过调用自定义dao层实现
        poschangerecordtableService.selectByMatid(matid,page);

        return R.ok().put("page", page);
    }


    @RequestMapping("/listselect")
    // @RequiresPermissions("poschangerecord:poschangerecordtable:list")
    public R listselect(@RequestParam Map<String, Object> params){
        // PageUtils page = poschangerecordtableService.queryPage(params);
        // 分页
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
        String mtype = String.valueOf(params.get("mtype"));
        Page<PoschangerecordtableEntity> page = new Page<>(pageIndex,pageSize);

        // 通过调用自定义dao层实现
        poschangerecordtableService.listselect(mtype,page);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{matid}")
    // @RequiresPermissions("poschangerecord:poschangerecordtable:info")
    public R info(@PathVariable("matid") String matid){
		PoschangerecordtableEntity poschangerecordtable = poschangerecordtableService.getById(matid);

        return R.ok().put("poschangerecordtable", poschangerecordtable);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   //  @RequiresPermissions("poschangerecord:poschangerecordtable:save")
    public R save(@RequestBody PoschangerecordtableEntity poschangerecordtable){
		poschangerecordtableService.save(poschangerecordtable);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("poschangerecord:poschangerecordtable:update")
    public R update(@RequestBody PoschangerecordtableEntity poschangerecordtable){
		poschangerecordtableService.updateById(poschangerecordtable);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("poschangerecord:poschangerecordtable:delete")
    public R delete(@RequestBody String[] matids){
		poschangerecordtableService.removeByIds(Arrays.asList(matids));

        return R.ok();
    }

}
